﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZXing;
using System.Drawing;
using System.Net;

namespace ShareMarking.Interface
{
    public class CheckQrcode
    {
        public string getqrcontent(string imgurl)
        {
            try
            {
                var reader = new BarcodeReader();
                Image O_Image = Image.FromStream(WebRequest.Create(imgurl).GetResponse().GetResponseStream());
                Result result = reader.Decode((Bitmap)O_Image); //通过reader解码
                if (result != null)
                {
                    return result.Text; //显示解析结果
                }
                return "";
            }
            catch (Exception ex)
            {
                ComLib.LogLib.Log4NetBase.Log("导出检查错误:"+ex.Message);
                return "";
            }
        }

        /// <summary>
        /// 读取二维码
        /// 读取失败，返回空字符串
        /// </summary>
        /// <param name="filename">指定二维码图片位置</param>
        public string Read1Decode(string filename)
        {
            try
            {
            BarcodeReader reader = new BarcodeReader();
            reader.Options.CharacterSet = "UTF-8";
            Bitmap map = new Bitmap(filename);
            Result result = reader.Decode(map);
            return result == null ? "" : result.Text;
            }
            catch (Exception ex)
            {
                ComLib.LogLib.Log4NetBase.Log("二维码解析错误:路径：" + filename + ex.Message);
                return "";
            }
        }
    }
}
